package com.zhaoc.web.action;

import com.opensymphony.xwork2.ActionContext;
import com.zhaoc.domain.system.Permission;
import com.zhaoc.service.IPermissionService;
import com.zhaoc.web.base.BaseAction;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * <p>title:com.zhaoc.web.action</p>
 * date:2018/8/22 0022
 * time:21:08
 * author:赵成
 * user:13566
 */
@ParentPackage("json-default")
public class PermissionAction extends BaseAction<Permission> {

    @Autowired
    private IPermissionService permissionService;

    //查询所有权限
    @Action(value = "permission_list", results = {@Result(name = SUCCESS, type = "json")})
    public String list() {
        List<Permission> permissions = permissionService.findAll();

        ActionContext.getContext().getValueStack().push(permissions);

        return SUCCESS;
    }

    //保存权限
    @Action(value = "permission_save", results = {@Result(name = SUCCESS, type = "redirect", location =
            "pages/system/permission.html")})
    public String save(){
        permissionService.save(model);
        return SUCCESS;
    }
}
